package pers.qianyu.month_202012.date_20201214;

import java.util.*;

/**
 * 646. 最长数对链
 * https://leetcode-cn.com/problems/maximum-length-of-pair-chain/
 *
 * @author mizzle rain
 * @date 2020-12-14 16:41
 */
public class FindLongestChain2 {
    /**
     * 贪心
     */
    public int findLongestChain(int[][] pairs) {
        if (pairs == null) {
            return 0;
        }
        int len = pairs.length;
        if (len == 1) {
            return 1;
        }
        Arrays.sort(pairs, (arr1, arr2) -> arr1[1] - arr2[1]);
        int res = 1;
        int[] temp = pairs[0];
        for (int i = 1; i < pairs.length; i++) {
            if (pairs[i][0] > temp[1]) {
                res++;
                temp = pairs[i];
            }
        }
        return res;
    }
}
